﻿
using Business.Base.Enums;
using Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Business.Base.Common
{
    public class DataSource
    {
        private string bindMember;
        private object bindValue;

        #region 静态初始化

        public const String EXPERIMENT_TYPE_DATASOURCE= "ExperimentType";
        public const String MOTORRATEDVOLTAGE = "MotorRatedVoltage";
        public const String WINDINGCONNECTION = "WindingConnection";
        public const String WINGDINGMATERIAL = "WindingMaterial";
        public const String FLOWMETER = "Flowmeter";
        public const String FLOWHEADLEVEL = "FlowHeadLevel";
        public const String PRESUREFLOWLEVEL = "PresureFlowLevel";
        public const String PHASEADDRESS = "PhaseAddress";


        static Dictionary<String, DataSource[]> dataSourceDic;
        public static Dictionary<string, DataSource[]> DataSourceDic { get => dataSourceDic;  }

        /*static DataSource()
        {
            initDataSource();
        }*/

        static DataSource[] initExperimentTypeDataSource()
        {
            DataSource[] dataSources = new DataSource[]
            {
                   new DataSource("离心泵性能测试",(object)ExperimentType.CentrifugalPumpPerf),
                   new DataSource("螺杆泵性能测试", (object)ExperimentType.ScrewPumpPerf),
                   new DataSource("汽蚀测试",(object)ExperimentType.NPSH),
                   new DataSource("空载测试", (object)ExperimentType.NoLoadTest),
                   new DataSource("升温测试",(object)ExperimentType.HighTemperature),
                   new DataSource("负载测试", (object)ExperimentType.LoadTest),
                   new DataSource("堵转测试", (object)ExperimentType.LockedRotorTest)
            };
            return dataSources;          
        }

        static DataSource[] initMotorRatedVoltage()
        {
            DataSource[] dataSources = new DataSource[]
            {
                   new DataSource("380",(int)MotorRatedVoltage.ThreePhase),
                   new DataSource("220", (int)MotorRatedVoltage.SinglePhase),
             
            };
            return dataSources;
        }

        static DataSource[] initWindingConnection()
        {
            DataSource[] dataSources = new DataSource[]
            {
                   new DataSource("三角形接法","三角形接法"),
                   new DataSource("星型接法", "星型接法"),

            };
            return dataSources;
        }
        
        static DataSource[] initWindingMaterial()
        {
            DataSource[] dataSources = new DataSource[]
            {
                   new DataSource("铜","铜"),
                   new DataSource("铝","铝"),

            };
            return dataSources;
        }

        static DataSource[] initFlowmeter()
        {
            string flowmeter = Config.Flowmeter;
            string[] configNode = flowmeter.Split(new char[] { ',' });

            DataSource[] flowmeterDataSource = new DataSource[configNode.Length];
            for (int i = 0; i < flowmeterDataSource.Length; i++)
            {
                string[] keyValue = configNode[i].Split(new char[] { ':' });
                flowmeterDataSource[i] = new DataSource(keyValue[0], int.Parse(keyValue[1]));
            }
            return flowmeterDataSource;
        }

        static DataSource[] initFlowHeadLevel()
        {
            DataSource[] dataSources = new DataSource[]
            {
                   new DataSource("1B",(object)FlowHeadLevel.FlowHeadLevel1B),
                   new DataSource("2B", (object)FlowHeadLevel.FlowHeadLevel2B),
                   new DataSource("3B", (object)FlowHeadLevel.FlowHeadLevel3B),

            };
            return dataSources;
        }

        static DataSource[] initPresureFlowLevel()
        {
            DataSource[] dataSources = new DataSource[]
            {
                   new DataSource("1B",(object)PresureFlowLevel.PresureFlowLevel1B),
                   new DataSource("2B", (object)PresureFlowLevel.PresureFlowLevel2B),
              

            };
            return dataSources;
        }


        public static void init()
        {
            dataSourceDic = new Dictionary<string, DataSource[]>();
            dataSourceDic.Add(EXPERIMENT_TYPE_DATASOURCE, initExperimentTypeDataSource());
            dataSourceDic.Add(MOTORRATEDVOLTAGE, initMotorRatedVoltage());
            dataSourceDic.Add(WINDINGCONNECTION, initWindingConnection());
            dataSourceDic.Add(WINGDINGMATERIAL, initWindingMaterial());
            dataSourceDic.Add(FLOWMETER, initFlowmeter());
            //dataSourceDic.Add(TRANSFORMATIONRATION, initTransformationRatio());
            dataSourceDic.Add(FLOWHEADLEVEL, initFlowHeadLevel());
            dataSourceDic.Add(PRESUREFLOWLEVEL, initPresureFlowLevel());
            dataSourceDic.Add(PHASEADDRESS, initPhaseAddress());
        }

        private static DataSource[] initPhaseAddress()
        {
            string phanseAddress = Config.PhaseInfo;
            string[] configNode = phanseAddress.Split(new char[] { ',' });

            DataSource[] phaseAddressDataSource = new DataSource[configNode.Length];
            for (int i = 0; i < phaseAddressDataSource.Length; i++)
            {
                string[] keyValue = configNode[i].Split(new char[] { ':' });
                phaseAddressDataSource[i] = new DataSource(keyValue[0], int.Parse(keyValue[1]));
            }
            return phaseAddressDataSource;
        }




        #endregion

        public DataSource(String bindMember, Object bindValue)
        {
            this.bindMember = bindMember;
            this.bindValue = bindValue;
        }

        [DataMember(Name = "BindMember")]
        public string BindMember { get => bindMember; set => bindMember = value; }

        [DataMember(Name = "BindValue")]
        public Object BindValue { get => bindValue; set => bindValue = value; }
}
}
